<template>
  <a-modal
    :title="title"
    :width="modalWidth"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :destroyOnClose="destoryClose"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-card :bordered="false">

      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="8" :sm="8">
              <a-form-item label="计量单位名称">
                <a-input placeholder="请输入计量单位名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <template v-if="toggleSearchStatus">
            </template>
            <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
      <!-- 操作按钮区域 -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: rowSelectType}"
          @change="handleTableChange"
          :customRow="rowFun"
        >
        </a-table>
      </div>
    </a-card>
  </a-modal>
</template>

<script>
  import { JeecgListMixin } from '@lone/lone-vue/src/mixins/JeecgListMixin'
  import { getAction} from '@lone/lone-vue/src/api/manage'

  export default {
    name: "MmsMaterialUnitModal",
    mixins: [JeecgListMixin],
    data () {
      return {
        title:"物资计量单位选择",
        dataSource:[],
        destoryClose:true,
        num:'',
        //下标
        index:-1,
        visible: false,
        modalWidth:800,
        confirmLoading: false,
        rowSelectType:'radio',
        description: '物资计量单位管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单位编码',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'单位名称',
            align:"center",
            dataIndex: 'name'
          },
        ],
        url: {
          list: '/base/mmsMaterialUnit/list'
        }
      }
    },
    created () {


    },
    methods: {
      showMmsMaterialUnitInfo(num,selectedRowKeys){
        this.num = num
        if(selectedRowKeys  !=''){
          this.selectedRowKeys = []
          this.selectedRowKeys.push(selectedRowKeys)
        }
        this.visible = true
      },
      handleOk(){
        if(this.index>=0){
          this.$emit("ok",this.selectionRows[0],this.index);
        }else{
          this.$emit("ok",this.selectionRows[0],this.num);

        }
        this.handleCancel();
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.index = 0
      },
      rowFun (record, index) {
        return {
          on: {
            dblclick: () => {
              this.$emit("ok",record,this.index)
              this.close()
            }
          }
        }
      }
    }
  }
</script>

<style lang="less" scoped>

</style>